﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Settings;
#endregion

namespace Rio.Framework.RioManager
{
    /// <summary>
    /// Class handle the managment of Settings
    /// </summary>
    public static class SettingsManager
    {

        #region Attributes
        /// <summary>
        /// Reference to an instance of StoreSettings class
        /// </summary>
        public static StoreSettings cStoreSettings { get { return m_cStoreSettings; } private set { m_cStoreSettings = value; } }
        private static StoreSettings m_cStoreSettings;
        public static IDictionary<string, string> DeploymentConfigurations {get; set;}

        #endregion

        #region Init
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// <param name="p_sPackageName">Package name (it's spécific for Oracle DB)</param>
        /// <remarks>packageName is optional</remarks>
        public static bool Init(string p_sPackageName)
        {
            bool l_bRet = false;

            try
            {
                List<Setting> l_oSettings = new List<Setting>();
                l_oSettings = SettingsRepository.Init(p_sPackageName);

                // Store all settings
                cStoreSettings = new StoreSettings();
                cStoreSettings.Parameter_OraclePackage = p_sPackageName;
                foreach (Setting oSetting in l_oSettings)
                {
                    try
                    {
                        cStoreSettings.AddParameter(Enums.eDescriptionAttributeToDomainSettings(oSetting.szDomain), Enums.eDescriptionAttributeToNameSettings(oSetting.szName), oSetting.szValue);
                    }
                    catch (Exception ex)
                    {
                        NetBay.Core.Log.LogManager.Instance().LogInfo("(PackageName<" + p_sPackageName + ">) unable to recognize Domain/Name( " + oSetting.szDomain + "/" + oSetting.szName + " ) EXCEPTION -> " + Environment.NewLine + ex);
                    }
                }
                // Dispatch values to properties
                cStoreSettings.DispatchParameter();
                l_bRet = true;
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("(PackageName<" + p_sPackageName + ">) EXCEPTION -> " + Environment.NewLine + ex);
            }
            return l_bRet;
        }

        
        #endregion

    }
}
